package com.fang.config.listener;

import com.fang.config.event.OrderProductEvent;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.time.Clock;

/**
 * 实现 ApplicationListener接口，并指定监听的事件类型
 * @author Fang Ruichuan
 * @date 2022-09-13 14:20
 */
@Slf4j
@Component
public class OrderProductListener implements ApplicationListener<OrderProductEvent> {

    @SneakyThrows
    @Override
    public void onApplicationEvent(OrderProductEvent event) {
        String orderId = event.getOrderId();
        long start = Clock.systemUTC().millis();
        Thread.sleep(2000);
        long end = Clock.systemUTC().millis();
        log.info("{}: 校验订单商品价格耗时：({})毫秒", orderId, (end - start));
    }
}
